//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbHinhThucDaoTao
    {
        public static DataTable Search(ETbHinhThucDaoTao htdt)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenHTDT", htdt.TenHTDT);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHinhThucDaoTao_Search", pr);
            return all;
        }

        public static bool KiemTraDuLieu(ETbHinhThucDaoTao htdt)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenHTDT", htdt.TenHTDT);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHinhThucDaoTao_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public static bool KiemTraDuLieu_Sua(ETbHinhThucDaoTao htdt)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenHTDT", htdt.TenHTDT);
            pr[1] = new SqlParameter(@"MaHTDT", htdt.MaHTDT);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHinhThucDaoTao_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
       
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHinhThucDaoTao_SelectAll", null);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbHinhThucDaoTao OTbHinhThucDaoTao)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenHTDT", OTbHinhThucDaoTao.TenHTDT);
            pr[1] = new SqlParameter(@"MoTa", OTbHinhThucDaoTao.MoTa);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHinhThucDaoTao_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbHinhThucDaoTao OTbHinhThucDaoTao)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaHTDT", OTbHinhThucDaoTao.MaHTDT);
            pr[1] = new SqlParameter(@"TenHTDT", OTbHinhThucDaoTao.TenHTDT);
            pr[2] = new SqlParameter(@"MoTa", OTbHinhThucDaoTao.MoTa);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHinhThucDaoTao_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaHTDT)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHTDT",MaHTDT);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHinhThucDaoTao_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbHinhThucDaoTao SelectByID(int MaHTDT)
        {
            ETbHinhThucDaoTao OTbHinhThucDaoTao = new ETbHinhThucDaoTao();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHTDT",MaHTDT);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbHinhThucDaoTao_SelectByID", pr);
            if (idr.Read())
              OTbHinhThucDaoTao = GetOneTbHinhThucDaoTao(idr);
            idr.Close();
            idr.Dispose();
            return OTbHinhThucDaoTao;
        }
//-----------------------------------------------------------//
        private static ETbHinhThucDaoTao GetOneTbHinhThucDaoTao(IDataReader idr)
       {
            ETbHinhThucDaoTao OTbHinhThucDaoTao = new ETbHinhThucDaoTao();
                if (idr["MaHTDT"] != DBNull.Value)
                    OTbHinhThucDaoTao.MaHTDT = (int)idr["MaHTDT"];
                if (idr["TenHTDT"] != DBNull.Value)
                    OTbHinhThucDaoTao.TenHTDT = (string)idr["TenHTDT"];
                if (idr["MoTa"] != DBNull.Value)
                    OTbHinhThucDaoTao.MoTa = (string)idr["MoTa"];
            return OTbHinhThucDaoTao;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaHTDT)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaHTDT",MaHTDT);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[2].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHinhThucDaoTao_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbHinhThucDaoTao> ListAll()
        {
            List<ETbHinhThucDaoTao> list = new List<ETbHinhThucDaoTao>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHinhThucDaoTao_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbHinhThucDaoTao(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}
